package com.springmvc.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * 配置自定义拦截器
 * 1.在此实现接口HandlerInterceptor
 * 2.在资源配置文件中配置
 */
public class FirstInterceptor implements HandlerInterceptor {
    /**
     *  此方法在目标方法之前执行
     *  如果返回值为true，则继续调用后续的拦截器和目标方法
     *  如果为false，则不会再调用
     *
     *
     *
     *  可以考虑做权限，事务，日志等等
     * @param httpServletRequest
     * @param httpServletResponse
     * @param o
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, Object o) throws Exception {
        return true;
    }

    /**
     * 此方法在目标方法之后，在渲染视图之前被调用
     *
     * 可以对请求域中的属性或者视图进行修改
     * @param httpServletRequest
     * @param httpServletResponse
     * @param o
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    /**
     * 此方法在渲染视图之后被调用
     *
     * 释放资源
     * @param httpServletRequest
     * @param httpServletResponse
     * @param o
     * @param e
     * @throws Exception
     */
    @Override
    public void afterCompletion(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}
